package com.ruoyi.information.controller.back;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.information.domain.back.ServiceArticleBack;
import com.ruoyi.information.service.back.IServiceArticleBackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 服务资讯Controller
 *
 * @author ruoyi
 * @date 2023-05-05
 */
@RestController
@RequestMapping("/serviceArticleBack")
public class ServiceArticleBackController extends BaseController
{
    @Autowired
    private IServiceArticleBackService serviceArticleService;

    /**
     * 查询服务资讯列表
     */
    @RequiresPermissions("information:serviceArticle:list")
    @GetMapping("/list")
    public TableDataInfo list(ServiceArticleBack serviceArticle)
    {
        startPage();
        List<ServiceArticleBack> list = serviceArticleService.selectServiceArticleList(serviceArticle);
        return getDataTable(list);
    }

    /**
     * 导出服务资讯列表
     */
    @RequiresPermissions("information:serviceArticle:export")
    @Log(title = "服务资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceArticleBack serviceArticle)
    {
        List<ServiceArticleBack> list = serviceArticleService.selectServiceArticleList(serviceArticle);
        ExcelUtil<ServiceArticleBack> util = new ExcelUtil<ServiceArticleBack>(ServiceArticleBack.class);
        util.exportExcel(response, list, "服务资讯数据");
    }

    /**
     * 获取服务资讯详细信息
     */
    @RequiresPermissions("information:serviceArticle:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceArticleService.selectServiceArticleById(id));
    }

    /**
     * 新增服务资讯
     */
    @RequiresPermissions("information:serviceArticle:add")
    @Log(title = "服务资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceArticleBack serviceArticle)
    {
        return toAjax(serviceArticleService.insertServiceArticle(serviceArticle));
    }

    /**
     * 修改服务资讯
     */
    @RequiresPermissions("information:serviceArticle:edit")
    @Log(title = "服务资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceArticleBack serviceArticle)
    {
        return toAjax(serviceArticleService.updateServiceArticle(serviceArticle));
    }

    /**
     * 删除服务资讯
     */
    @RequiresPermissions("information:serviceArticle:remove")
    @Log(title = "服务资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceArticleService.deleteServiceArticleByIds(ids));
    }
}
